clear all
*Define directory
cap cd "...\Replication pacakage\"

use data.dta
replace Year="2012" if Year=="2012 (Sandy)"
destring Year,force replace
keep if Year>2002


*Regular EIDL summary stats
preserve
keep if ApprovedAmountEIDL>0
*generate number of EIDL loans by zipcode
bysort DamagedPropertyZipCode: egen no1=count(ApprovedAmountEIDL)
*generate number of EIDL loans by disaster
bysort SBAEIDLDeclarationNumber: egen no2=count(ApprovedAmountEIDL)
est clear  // clear the est locals
estpost tabstat ApprovedAmountEIDL EIDL no2 no1, stat(mean sd p10 p50 p90 count) columns(statistics)
esttab using "./Table 1/table 1b.tex", replace ///
cells("mean(fmt(%13.2fc)) sd(fmt(%13.2fc)) p10(fmt(%13.2fc)) p50(fmt(%13.2fc)) p90(fmt(%13.2fc)) count(fmt(%13.0fc))") nonumber ///
 nomtitle nonote noobs label collabels("Mean" "Std.Dev." "10th Pctl." "Median" "90th Pctl." "Observations")
restore


*BPDL summary stats
preserve
keep if TotalApprovedLoanAmount>0
*generate number of BPDL loans by zipcode
bysort DamagedPropertyZipCode: egen no1=count(ApprovedAmountEIDL)
*generate number of BPDL loans by disaster
bysort SBAPhysicalDeclarationNumber: egen no2=count(ApprovedAmountEIDL)
est clear  // clear the est locals
estpost tabstat TotalApprovedLoanAmount PDBL TotalVerifiedLoss no2 no1, stat(mean sd p10 p50 p90 count) columns(statistics)
esttab using "./Table 1/table 1a.tex", replace ///
cells("mean(fmt(%13.2fc)) sd(fmt(%13.2fc)) p10(fmt(%13.2fc)) p50(fmt(%13.2fc)) p90(fmt(%13.2fc)) count(fmt(%13.0fc))") nonumber ///
 nomtitle nonote noobs label collabels("Mean" "Std.Dev." "10th Pctl." "Median" "90th Pctl." "Observations")
restore

*COVID EIDL summary stats
use EIDL_raw.dta, clear
keep legalentityzip5 facevalueofdirectloanorloanguara actiontype businesstypes
keep if actiontype =="A"
keep if businesstypes=="R"|businesstypes=="PR"
*generate number of COVID EIDL loans by zipcode
bysort legalentityzip5: egen no1=count(facevalueofdirectloanorloanguara)
*COVID EIDL has a fixed interest rate at 3.75% for all loans.
g rate=3.75
est clear  // clear the est locals
estpost tabstat facevalueofdirectloanorloanguara rate no1, stat(mean sd p10 p50 p90 count) columns(statistics)
esttab using "./Table 1/table 1c.tex", replace ///
cells("mean(fmt(%13.2fc)) sd(fmt(%13.2fc)) p10(fmt(%13.2fc)) p50(fmt(%13.2fc)) p90(fmt(%13.2fc)) count(fmt(%13.0fc))") nonumber ///
 nomtitle nonote noobs label collabels("Mean" "Std.Dev." "10th Pctl." "Median" "90th Pctl." "Observations")
